var database = require('../../data/data.js');
Page({
  data: {
    finish1: false,
    finish2: false,
    flag: true,
  },
  onLoad: function (options) {

  },
  submit: function (e) {
    var that = this;
    wx.request({
      url: database.url1 + '/api/V2/user/access_token',
      data: {
        clientId: "QqKTO5BTPN6REI26QAgq",
        clientSecret: "F2MjbLO88FMiwr3pTOXylnjURAOzvqLJXSFMeJUg"
      },
      success(res) {
        console.log()
        database.accessToken = res.data.data.accessToken;
        wx.request({
          url: database.url1 + '/api/V2/user/binding_wechat_small',
          method: "POST",
          header: {
            'content-type': 'application/x-www-form-urlencoded'
          },
          data: {
            username: e.detail.value.tel,
            password: e.detail.value.password,
            accessToken: database.accessToken,
            unionid: database.unionid,
            smscode: "smscode"
          },
          success(res) {
            console.log(res)
            if (!res.data.status) {
              that.setData({
                flag: false,
                registered_status_text: res.data.status_reason
              })
            } else {
              database.id = res.data.data.userId;
              database.login = true;
              wx.navigateTo({
                url: "/pages/home/home"
              })
            }
          }
        })
      }
    })
  },
  tel: function (e) {
    if (e.detail.value.length == 11) {
      this.setData({
        finish1: true,
        tel: e.detail.value
      })
    } else {
      this.setData({
        finish1: false
      })
    }
  },
  psd: function (e) {
    if (e.detail.value.length != "") {
      this.setData({
        finish2: true,
        psd: e.detail.value
      })
    } else {
      this.setData({
        finish2: false
      })
    }
  },
  know: function (e) {
    this.setData({
      flag: true
    })
  }
})